package com.gsn.common;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.ClickListener;
import com.badlogic.gdx.scenes.scene2d.ui.GsnImageButton;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.gsn.desktop.engine.ActorUtility;
import com.gsn.engine.gdx.GsnParticleActor;
import com.gsn.engine.myplay.GsnLayer;
import com.gsn.engine.utility.UtilityGettor;
import com.gsn.login.LoginScreen;
import com.gsn.name.NameEdit;
import com.gsn.poker.asset.FontTexture;
import com.gsn.poker.asset.PokerSound;
import com.gsn.poker.asset.PortalTexture;
import com.gsn.poker.game.MyPoker;

public class PortalHelpLayer extends GsnLayer implements ClickListener {
	private static final String tag = "DialogLayer";
	float time = 0.5f;
	protected ParticleEffect clickEff;

	public PortalHelpLayer(float width, float height) {
		super(width, height);
		PortalTexture portalTexture = PortalTexture.inst();

		Image bgDark = new Image(portalTexture.bgDarkDialog);
		portalTexture.scaleActor(bgDark);
		addActor(bgDark);
		bgDark.width = width;
		bgDark.height = height;

		Image bg = new Image(portalTexture.bgDialog);
		portalTexture.scaleActor(bg);
		addActor(bg);
		bg.x = (width - bg.width) / 2;
		bg.y = (height - bg.height) / 2;

		GsnImageButton close = new GsnImageButton(portalTexture.closeButton, portalTexture.closeButtonPress);
		portalTexture.scaleActor(close);
		addActor(close);
		close.x = bg.x + bg.width - close.getRealWidth() * 1.4f;
		close.y = bg.y + bg.height - close.getRealHeight() * 1.1f;
		close.setClickListener(this);

		clickEff = portalTexture.clickEff;

		Label labelTitle = new Label("Trợ giúp", new Label.LabelStyle(FontTexture.inst().fontMedium, new Color(1, 1, 1, 1)));
		addActor(labelTitle);
		labelTitle.x = bg.x + bg.width * 0.05f;
		labelTitle.y = bg.y + bg.height * 0.92f;

		Label labelHelp = new Label("Mọi ý kiến – thắc mắc về game, các bạn vui lòng liên hệ với bộ phận hỗ " + "trợ khách hàng của myPlay theo hai cách:\n" + "-	Gọi hỗ trợ: 1900561558 \n" + "-	Truy cập vào diễn đàn \n" + "Rất cảm ơn sự đóng góp của các bạn. Chúc các bạn có những giây phút giải trí thật thoải mái với myPlay.", new Label.LabelStyle(FontTexture.inst().fontMedium, new Color(1, 1, 1, 1)));
		labelHelp.width = bg.width * 0.9f;
		labelHelp.setWrap(true);

		addActor(labelHelp);
		labelHelp.x = bg.x + bg.width * 0.05f;
		labelHelp.y = bg.y + (bg.height - labelHelp.height) / 2;
	}

	@Override
	public void click(Actor actor, float x, float y) {
		// TODO Auto-generated method stub
		hide();
		if (clickEff != null) {
			Vector2 v = ActorUtility.getCoordinate(actor, x, y, this.root);
			GsnParticleActor par = new GsnParticleActor(clickEff);
			par.setPostition(v.x, v.y);
			par.start();
			this.addActor(par);
		}
		PokerSound.playClick();
	}

	public InputProcessor oldInput;

	public void show() {
		oldInput = Gdx.input.getInputProcessor();
		visible = true;
		setInputListener();
	}

	public void hide() {
		Gdx.input.setInputProcessor(oldInput);
		oldInput = null;
		visible = false;
		
		if(MyPoker.game.currentScreen instanceof LoginScreen)
		{
			UtilityGettor.inst().visibleTextField(NameEdit.NAME_USER);
			UtilityGettor.inst().visibleTextField(NameEdit.PASS_USER);
		}
	}

}
